#
# This is merely an extension of the Lockdown::Permissions module to
# allow for database manipulation of Permissions
#
# This is typically done via management screens.
#
class Permission < ActiveRecord::Base
  has_and_belongs_to_many :user_groups
  
  before_save :ensure_lockdown_permission_exists
  
  protected
    #
    # Cannot create a permission record in the db that is not defined
    # in config/initializers/lock_down_access
    #
    # Creating a db record is to simplify the creation of user groups
    # via management screens.
    #
    def ensure_lockdown_permission_exists
      unless Lockdown::Permissions.respond_to?(self.name.to_title_sym)
        raise NameError.new("#{sym} is not defined.")
      end
    end
    
end
